package com.inspire.springboot.util;

import java.util.*;

/**
 * @author ：inspire
 * @date ：Created in 2022/11/9 9:29
 * @description：
 * @modified By：inspire
 * @version:
 */
public class ZoaAccessSqlParamsUtil {
    public static Stack<Map<Integer,Object>> sqlContentStack =new Stack<Map<Integer,Object>>();

    //old
//    static Map<Integer,Object> accessSqlParamsMap=new HashMap<Integer,Object>();

    public static void initial(){

    }


    // batch
    public static void setNewMapInQueue(){
        Map<Integer,Object> map=new HashMap<>();
        sqlContentStack.push(map);
    }

    public static void put(int index,Object param){
        if(sqlContentStack.empty()){//第一次set******()
            Map<Integer, Object> map=new HashMap<>();
            map.put(index,param);
            sqlContentStack.push(map);
        }else{//之后的批处理
            sqlContentStack.peek().put(index,param);
        }
    }
    public static void put(int index,int param){
        if(sqlContentStack.empty()){//第一次set******()
            Map<Integer, Object> map=new HashMap<>();
            map.put(index,param);
            sqlContentStack.push(map);
        }else{//之后的批处理
            sqlContentStack.peek().put(index,param);
        }    }
    /*public static void put(int index,long param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,short param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,double param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,boolean param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,byte[] param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,float param){
        accessSqlParamsMap.put(index,param);
    }
    public static void put(int index,byte param){
        accessSqlParamsMap.put(index,param);
    }*/

    public static Stack<Map<Integer,Object>> get(){
        if(sqlContentStack.size()!=0&&sqlContentStack.peek()!=null&&sqlContentStack.peek().size()==0){//栈顶的Map对象没有存储内容，则pop
            System.out.println("peek is null!");
            sqlContentStack.pop();
        }

        return sqlContentStack;
    }
}
